﻿using Game.Entity.Accounts;
using Game.Facade;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;

namespace Game.Card
{
    public class AdminPage : Page
    {
        /// <summary>
        /// 用户基本Cookies信息
        /// </summary>
        protected UserTicketInfo userTicket;

        /// <summary>
        /// 初始化并验证用户身份
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if(Fetch.IsUserOnline())
            {
                userTicket = Fetch.GetUserCookie();
            }
            else
            {
                string url = String.Format("/Login.aspx?url={0}", HttpUtility.UrlEncode(Utils.GameRequest.GetUrl()));
                Response.Redirect(url);
                Response.End();
            }
        }

        #region 消息对话框

        /// <summary>
        /// 显示消息提示对话框
        /// </summary>
        /// <param name="msg">提示信息</param>
        public void ShowInfo(string msg)
        {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script type='text/javascript'>layer.open({content: '"+ msg +"',skin: 'footer'});</script>");
        }

        /// <summary>
        /// 控件点击 消息确认提示框
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
        {
            Control.Attributes.Add("onclick", "return confirm('" + msg + "');");
        }

        /// <summary>
        /// 显示消息提示对话框，并进行页面跳转
        /// </summary>
        /// <param name="page">当前页面指针，一般为this</param>
        /// <param name="msg">提示信息</param>
        /// <param name="url">跳转的目标URL</param>
        public void ShowAndRedirect(string msg, string url)
        {
            StringBuilder Builder = new StringBuilder();
            Builder.Append("<script language='javascript' defer>");
            Builder.AppendFormat("alert('{0}');", msg);
            Builder.AppendFormat("top.location.href='{0}'", url);
            Builder.Append("</script>");
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", Builder.ToString());

        }

        #endregion

        #region 时间格式化
        public string GetFormatTime(object obj)
        {
            if(obj != null)
            {
                DateTime time = Convert.ToDateTime(obj);
                return time.ToString("yyyy-MM-dd") + "<br/>" + time.ToString("HH:mm:ss");
            }
            return "";
        }
        #endregion
    }
}